﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AzureTest;

namespace AzureTest.Controllers
{
    public class HomeController : Controller
    {        
        //
        // GET: /Home/
        // anything passed as an argument to Index will be from a GET request
        public ActionResult Index(string name)
        {
            if (name != null)
            {
                // create model of data
                TestDataModel data = new TestDataModel("Data", name);
                data.Data = name;
                data.Method = "GET";

                // insert it into table
                TestDataSource tds = new TestDataSource();
                tds.Insert(data);
            }
            ViewBag.Message = "You entered: " + name;

            return View();
        }

        // anything passed as an argument to Post will be from a POST request
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Post(string name)
        {
            // create model of data
            TestDataModel data = new TestDataModel("Data", name);
            data.Data = name;
            data.Method = "POST";

            // insert it into table
            TestDataSource tds = new TestDataSource();
            tds.Insert(data);

            return View("Index");
        }

        //
        // GET: /Home/Root
        public ActionResult Root()
        {
            TestDataSource tds = new TestDataSource();
            IEnumerable<TestDataModel> items = tds.Select();
            
            ViewBag.Items = items;

            return View();
        }
    }
}
